package com.globalblue;

import java.util.Date;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import com.globalblue.services.ServiceFileDownloader;

@WebServlet("/StartupController")
public class StartupController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	public static Logger logger = Logger.getLogger(StartupController.class);

	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		try {
			ServiceFileDownloader downloader = new ServiceFileDownloader();
			StartupConstants.setServiceIpList(downloader.getAllServerIpList());
			downloader.downloadFiles(StartupConstants.getServiceIpList());
			StartupConstants.setLastUpdatedTime(new Date());
		} catch (Exception e) {
			logger.log(Level.ERROR, e);
		}
	}
}
